package com.wthink.hzgj.service.jt808

import android.util.Log
import com.wthink.hzgj.data.domain.CheckinType
import com.wthink.hzgj.util.BCD
import com.wthink.hzgj.util.PreferencesUtils
import java.math.BigDecimal
import java.nio.ByteBuffer
import java.text.SimpleDateFormat
import java.util.*

class JT_0B09 (var line: Int, var user: String, var business: Int
) : JT808Message()  {

    /*   var time: String = SimpleDateFormat("yyMMdd").format(
           Date())
   */
    init {
        messageType = "0b09"
    }

    override fun writeToBytes(): ByteArray {
        val buf = ByteBuffer.allocate(23 + user.length)
        buf.putInt(line)
        buf.put(user.toByteArray())
        buf.put(0)
        buf.put(business.toByte())
        val toByte = business.toByte()

/*
        when (business) {
            "排班"->{buf.put(1)}
            "交班"->{buf.put(2)}
            "加油"->{buf.put(3)}
            "加气"->{buf.put(4)}
            "充电"->{buf.put(5)}
            "维修"->{buf.put(6)}
            "包车"->{buf.put(7)}
            "终止任务"->{buf.put(8)}
        }
*/
        val sdf = SimpleDateFormat("yyMMddHHmmss")
        val mix = PreferencesUtils.getLong("mix")
        val nowTime : BigDecimal = BigDecimal(mix).add(BigDecimal(System.currentTimeMillis()))
        val time =sdf.format(nowTime)
        Log.d("当前时间",time)
        buf.put(BCD.ASCII_To_BCD(time.toByteArray(), time.length))
        // buf.put(1)
        buf.flip()
        val body = ByteArray(buf.remaining())
        buf.get(body)
        return body
    }
}